/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "stub.h"
#include <protect_engines/kubernetes/util/Transformer.h>
#include <protect_engines/kubernetes/common/KubeErrorCodes.h>

namespace HDT_TEST {
using ::testing::_;
using ::testing::Return;
using ::testing::ReturnRef;
using namespace KubernetesPlugin;
std::pair<int32_t, std::shared_ptr<StorageClient>> Stub_StorageClientCreate(const std::string &ip, int port,
    const AccessAuthParam &accessAuthParam, const std::vector<std::string> &ipList)
{
    StorageDeviceAuthData authData = {"", "", {""}};
    std::shared_ptr <StorageClient> dummy = std::make_shared<StorageClient>(ip, port, accessAuthParam, authData, ipList);
    if (ip == "127.0.0.1" && port == 8088 &&
        accessAuthParam.m_userName == "abc" && accessAuthParam.m_userkey == "123") {
        return std::make_pair(0, dummy);
    } else {
        return std::make_pair(Module::FAILED, dummy);
    }
}

class TransformerTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    static void SetUpTestCase();
    static void TearDownTestCase();

};

void TransformerTest::SetUp() {}
void TransformerTest::TearDown() {}
void TransformerTest::SetUpTestCase() {}
void TransformerTest::TearDownTestCase() {}

/**
 * 测试用例：测试FulfillVolInfo函数成功
 * 前置条件：预置正常的数据
 * Check点：VolInfo被正确填充。
 */
TEST_F(TransformerTest, FulfillVolInfoShouldSuccess) {
    VolInfo targetVolInfo;

    StorageDeviceInfo storageDeviceInfo;
    LunInfoData lunInfoData;
    lunInfoData.m_sectorSize = "512";
    lunInfoData.m_capacity = "128";
    StorageParam storageParam;
    storageParam.ip = "127.0.0.1";
    KubeHelper::FulfillVolInfo(targetVolInfo,
                               storageDeviceInfo,
                               lunInfoData,
                               storageParam);
    EXPECT_EQ(targetVolInfo.m_datastore.m_ip, storageParam.ip);
}

/**
 * 测试用例：测试GetStorageParamVecFromAppEnv函数成功
 * 前置条件：预置正常的数据
 * Check点：返回正确的StorageParamList。
 */
TEST_F(TransformerTest, GetStorageParamVecFromAppEnv_ShouldSuccess) {
    std::string authExtendInfo = R"({"config":"123","storages":"[{\"username\": \"test\",\"password\": \"test\",\"ip\": \"8.40.111.70\",\"port\": 8088},{\"username\": \"test\",\"password\": \"test\",\"ip\": \"127.0.0.1\",\"port\": 8088}]"})";
    auto storageOptList = KubeHelper::GetStorageParamVecFromAppEnv(authExtendInfo);
    EXPECT_TRUE(storageOptList);
    EXPECT_EQ(storageOptList->size(), 2);
    EXPECT_EQ((*storageOptList)[1].ip, "127.0.0.1");
}

/**
 * 测试用例：测试GetKubernetesApiFromAppEnv函数成功
 * 前置条件：config参数正常
 * Check点：返回正确的KubernetesApi。
 */
TEST_F(TransformerTest, GetKubernetesApiFromAppEnv_ShouldSuccess) {
    std::string authExtendInfo = R"({"config":"a2luZDogQ29uZmlnCmFwaVZlcnNpb246IHYxCmNsdXN0ZXJzOgotIGNsdXN0ZXI6CiAgICBjZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YTogTFMwdExTMUNSVWRKVGlCRFJWSlVTVVpKUTBGVVJTMHRMUzB0Q2sxSlNVaE9la05EUWxJclowRjNTVUpCWjBsS1FVMXZhblpFUVZWYVJrWnJUVUV3UjBOVGNVZFRTV0l6UkZGRlFrTjNWVUZOU1Vjd1RWRnpkME5SV1VRS1ZsRlJSMFYzU2tSVWFrVlRUVUpCUjBFeFZVVkRRWGRLVWpOV2FHSnRaRVZpTWpWdVRWSkZkMFIzV1VSV1VWRklSRUZvVkdGSFZuVlhiV2hzWW1wRmJBcE5RMDFIUVRGVlJ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hqT0V4RlJqQTJUMDlsYkROcENrTjVRbE5IWm1GMmRVdzJNbU5xVTNVM2VucFZaelZKYWtWaFZqSnpORVZEWjJkRlFVWndXWFJSYVZWbWMwVkxOV0ZUVms0cldHWlFUMmhWYlV0VlFrUUtVVkprY2tObmFISXJja2hDUnpjdmJESkhSMDlTY1RCMkwydEJjMHR5TldSUllXOXBMMHBaUnpOeVMwTTJZMmcyVm1sck5GQllOUzlhVEVWRlZsWkROQXB3VFZwVmNWbDNWMDh4Y0VGeFUza3JNMjUwYjNoSmRFUk5NWEZ2ZEc4eFVuVnVPV1kwTVROWWFVNDFXbkpEUVRWTmFYbzBiR2hwV2xoaWREQkRkalUyQ2toWE4xbG5WRWRXZDBsWVltSnFTM05MTmtadVJIQkJlbkZwYVZNd1NHZFNWMFp6UWtVd1JWSmlTekpWYTNOMmFVdEhVV3AzUlVaU1ZrMXNjR3BzUTFRS2MxUmxaalJIYkd0V2NraDFiVkkzZDNobWFUVmpORmhMVWxoR1RuZEZObkoxZUdoa1RrZHFUV3BsTW5wTE5uSnZSVlpMVTNCdWFXSjBTMHBKWVZsVmN3cEVla1ZGZUZRM2VIRTRVR3RMY2tSMmJWWlZVbGQxWjFoV2NuQTNObGRUTW5vemNHUkhibFZRU1dkVFdraHJjM3BhTVdGS01HZEpOWEJSUFQwS0xTMHRMUzFGVGtRZ1VsTkJJRkJTU1ZaQlZFVWdTMFZaTFMwdExTMEsKY29udGV4dHM6Ci0gY29udGV4dDoKICAgIGNsdXN0ZXI6IGNsdXN0ZXIKICAgIHVzZXI6IGNmZS1tYXN0ZXIKICBuYW1lOiBkZWZhdWx0Q29udGV4dApjdXJyZW50LWNvbnRleHQ6IGRlZmF1bHRDb250ZXh0Cg==","storages":"[{\"username\": \"test\",\"password\": \"test\",\"ip\": \"8.40.111.70\",\"port\": 8088},{\"username\": \"test\",\"password\": \"test\",\"ip\": \"127.0.0.1\",\"port\": 8088}]"})";
    auto k8sApi = KubeHelper::GetKubernetesApiFromAppEnv(authExtendInfo);
    EXPECT_TRUE(k8sApi);
}

/**
 * 测试用例：测试GetKubernetesApiFromAppEnv函数失败
 * 前置条件：config参数错误
 * Check点：返回空的KubernetesApi。
 */
TEST_F(TransformerTest, GetKubernetesApiFromAppEnv_ShouldFailed) {
    std::string authExtendInfo = R"({"config":"123","storages":"[{\"username\": \"test\",\"password\": \"test\",\"ip\": \"8.40.111.70\",\"port\": 8088},{\"username\": \"test\",\"password\": \"test\",\"ip\": \"127.0.0.1\",\"port\": 8088}]"})";
    auto k8sApi = KubeHelper::GetKubernetesApiFromAppEnv(authExtendInfo);
    EXPECT_FALSE(k8sApi);
}

/**
 * 测试用例：测试GetStorageClientFromStorageParam函数成功
 * 前置条件：认证参数正常。
 * Check点：错误码为0。
 */
TEST_F(TransformerTest, GetStorageClientFromStorageParam_ShouldSuceess) {
    Stub stub;
    stub.set(ADDR(StorageClient, Create), Stub_StorageClientCreate);
    StorageParam storageParam;
    storageParam.username = "abc";
    storageParam.password = "123";
    storageParam.ip = "127.0.0.1";
    storageParam.ipList = "127.0.0.1,127.0.0.2";
    storageParam.port = 8088;
    // auto [ret, storageClient] = KubeHelper::GetStorageClientFromStorageParam(storageParam);
    // EXPECT_EQ(ret, Module::SUCCESS);
}

/**
 * 测试用例：测试GetStateFulSetFromExtendInfo函数成功
 * 前置条件：认证参数正常。
 * Check点：错误码为0。
 */
TEST_F(TransformerTest, GetStateFulSetFromExtendInfo_ShouldSuceess) {
    std::string appExtendInfo = "{\"sts\":\"{\\\"id\\\":\\\"3bb6d270-0f6d-4f0b-bea1-bccc5332163b\\\",\\\"name\\\":\\\"adaptermdb-1-1-m\\\",\\\"nameSpace\\\":\\\"ns000000000000000000001\\\",\\\"pods\\\":[{\\\"name\\\":\\\"adaptermdb-1-1-m-0\\\",\\\"pvs\\\":[{\\\"lunName\\\":\\\"1-adaptermdb-1-1-m-0-backup\\\",\\\"name\\\":\\\"pv-adaptermdb-1-1-m-0-backup\\\",\\\"pvcName\\\":\\\"gmdbbackup-adaptermdb-1-1-m-0\\\",\\\"size\\\":\\\"50Gi\\\",\\\"storageUrl\\\":\\\"https://8.40.111.70:8088/deviceManager/rest\\\",\\\"volumeName\\\":\\\"gmdbbackup\\\"},{\\\"lunName\\\":\\\"1-adaptermdb-1-1-m-0-redo\\\",\\\"name\\\":\\\"pv-adaptermdb-1-1-m-0-redo\\\",\\\"pvcName\\\":\\\"gmdbredo-adaptermdb-1-1-m-0\\\",\\\"size\\\":\\\"85Gi\\\",\\\"storageUrl\\\":\\\"https://8.40.111.70:8088/deviceManager/rest\\\",\\\"volumeName\\\":\\\"gmdbredo\\\"},{\\\"lunName\\\":\\\"1-adaptermdb-1-1-m-0-data\\\",\\\"name\\\":\\\"pv-adaptermdb-1-1-m-0-data\\\",\\\"pvcName\\\":\\\"gmdbdata-adaptermdb-1-1-m-0\\\",\\\"size\\\":\\\"80Gi\\\",\\\"storageUrl\\\":\\\"https://8.40.111.70:8088/deviceManager/rest\\\",\\\"volumeName\\\":\\\"gmdbdata\\\"},{\\\"lunName\\\":\\\"1-adaptermdb-1-1-m-0-lredo\\\",\\\"name\\\":\\\"pv-adaptermdb-1-1-m-0-lredo\\\",\\\"pvcName\\\":\\\"gmdblredo-adaptermdb-1-1-m-0\\\",\\\"size\\\":\\\"85Gi\\\",\\\"storageUrl\\\":\\\"https://8.40.111.70:8088/deviceManager/rest\\\",\\\"volumeName\\\":\\\"gmdblredo\\\"}]}],\\\"replicasNum\\\":1,\\\"volumeNames\\\":[\\\"gmdbredo\\\",\\\"gmdbdata\\\",\\\"gmdblredo\\\",\\\"gmdbbackup\\\"]}\\n\"}\n";
    auto stateFulSet = KubeHelper::GetStateFulSetFromExtendInfo(appExtendInfo);
    EXPECT_TRUE(stateFulSet);
    EXPECT_EQ(stateFulSet->name, "adaptermdb-1-1-m");
    EXPECT_EQ(stateFulSet->pods[0].pvs.size(), 4);
}

}
